﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project362.Files;
using System.Runtime.Serialization;

namespace Project362.Tags
{
    [Serializable()]
    public class Tag : ISerializable
    {
		private string tag;
        public string Name { get { return tag; } }
		private Dictionary<string,FileClass> directory;
		public Tag(string tag){
			this.tag=tag;
			this.directory=new Dictionary<string, FileClass>();
		}
        public Tag(SerializationInfo info, StreamingContext stream)
        {
            this.directory = (Dictionary<string, FileClass>)info.GetValue("Dictionary", typeof(Dictionary<string, FileClass>));
            this.tag = (string)info.GetValue("Tag", typeof(string));
        }
		public override string ToString ()
		{
			 return this.tag;
		}
		public bool addFile(FileClass f){
			if(!directory.ContainsKey(f.Filename)){
				this.directory.Add(f.Filename, f);
				return true;
			} else return false;
		}
		public bool removeFile(FileClass f){
			if(directory.ContainsKey(f.Filename)){
				this.directory.Remove(f.Filename);
				return true;
			} else return false;
		}
		public List<FileClass> getFiles(){
			List<FileClass> l=new List<FileClass>();
			foreach(KeyValuePair<string,FileClass> kvp in directory){
				l.Add (kvp.Value);
			}
			return l;
		}
        public void GetObjectData(SerializationInfo info, StreamingContext stream)
        {
            info.AddValue("Dictionary", directory);
            info.AddValue("Tag", tag);
        }
    }
}
